<?php
    class Admin_Model_Comment extends Zend_Db_Table_Abstract
    {
        protected $_name = 'comment';
        protected $_primary = 'comment_id';
        protected $_db;
        
        public function __construct() {
            $this->_db = Zend_Registry::get('db');
        }
        
        public function listComment() {
            $user = array(
                'u.fullname',
            );
            $tour = array(
                't.tour_name',
            );
            $comment = array(
                'c.comment_id',
                'c.create_date',
                'c.status',
            );
            $sql = $this->_db->select()
                            ->from('comment AS c', $comment)
                            ->join('user AS u', 'u.user_id = c.user_id', $user)
                            ->join('tour AS t', 't.tour_id = c.tour_id', $tour)
                            ->order('c.comment_id DESC');
            return $sql;
        }
        
        public function getCommentById($comment_id) {
            $user = array(
                'u.fullname',
            );
            $tour = array(
                't.tour_name',
            );
            $comment = array(
                'c.comment_id',
                'c.term',
                'c.create_date',
                'c.status',
            );
            $sql = $this->_db->select()
                            ->from('comment AS c', $comment)
                            ->join('user AS u', 'u.user_id = c.user_id', $user)
                            ->join('tour AS t', 't.tour_id = c.tour_id', $tour)
                            ->where('c.comment_id = ?', $comment_id);
            $result = $this->_db->fetchRow($sql);
            return $result;
        }
        
        public function editComment($comment_id, $data) {
            $where = $this->getAdapter()->quoteInto('comment_id = ?', $comment_id);
            $this->_db->update($this->_name, $data, $where);
        }
        
        public function deleteComment($comment_id) {
            $where = $this->getAdapter()->quoteInto('comment_id = ?', $comment_id);
            $this->_db->delete($this->_name, $where);
        }
        
        public function deleteComments($listId) {
            foreach($listId as $value) {
                $where = $this->getAdapter()->quoteInto('comment_id = ?', $value);
                $this->_db->delete($this->_name, $where);
            }
        }
    }
